<?php
/**
 * Descript:
 * User: lufeng501206@gmail.com
 * Date: 2017/3/24 22:31
 */

namespace App\Repositories;

include app_path() . '/Libraries/3rdclasses/alidayuSDK/TopSdk.php';

class AliRepos
{
    public function sendCode($mobile)
    {
        $code = rand(000001, 999999);
        \Log::alert('验证码：'.$code);
        $client = new \TopClient;
        $client->appkey = env('SMS_APP_KEY');
        $client->secretKey = env('SMS_SECRET_KEY');
        $request = new \AlibabaAliqinFcSmsNumSendRequest;
        $request->setExtend("");
        $request->setSmsType("normal");
        $request->setSmsFreeSignName(env('SMS_SIGN'));
        $request->setSmsParam("{code:'" . $code . "'}");
        $request->setRecNum($mobile);
        $request->setSmsTemplateCode(env('SMS_TEMPLATE'));
        if(env('SMS_SWITCH')) {
            $resp = $client->execute($request);
            if (!empty($resp->result) && $resp->result->success) {
                return $code;
            } else {
                return false;
            }
        }else{
            return $code;
        }

    }
}